package com.shujia.wyh.day21;

import java.util.Comparator;

public class Student2 implements Comparator<Student2> {
    private String name;
    private int age;

    public Student2() {
    }

    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compare(Student2 o1, Student2 o2) {
        //主要条件：姓名的长短
        int i = o1.name.length() - o2.name.length();
        //隐含条件
        //姓名长度一样，内容不一定一样
        int i2 = (i == 0) ? o1.name.compareTo(o2.name) : i;
        //姓名一样，年龄还不一定一样
        int i3 = (i2 == 0) ? o1.age - o2.age : i2;

        return i3;
    }
}
